<?php
	require_once 'SignService.class.php';
	
	//接收用户名和密码
	$comment = isset($_POST['comment'])?$_POST['comment']:"";
	$action = isset($_GET['act'])?$_GET['act']:"signin";
	//准备工作
	session_start();
	$signServ = new SignService();
	
	if(empty($_SESSION['loginuser']))
	{
		header("Location: login.php");
		exit();
	}
	$username = $_SESSION['loginuser'];

	if($action === "signin" )
	{
		$res = $signServ->signIn($username, $comment);
		if($res <= 0)
		{
			if($res == -1)
				$_SESSION['sign_res'] = "签到截止时间已过，请自动上交今天罚款。";
			if($res == -2)
				$_SESSION['sign_res'] = "你今天已签到过！";
			if($res == -3)
				$_SESSION['sign_res'] = "请在5点之后进行签到！";
		} else {
			$_SESSION['sign_res'] = "签到成功！";
		}
		header("Location: sign.php");
		exit();		
	}
	if($action === "countsigns")
	{
		//file_put_contents('d:\mylog.txt', '是否进入countsigns controller？');
		$begin = isset($_GET['current'])?$_GET['current'].'-01':date('y-m').'-01';
		$end = isset($_GET['current'])?$_GET['current'].'-31':date('y-m').'-31';
		echo $signServ->getSignTimes($username, $begin, $end);
	}

	if($action === "topLate")
	{
		echo $signServ->getTopLate();
	}


?>